#pragma once

#include "UMLStateMachineDiagram.h"

#include "../uml/StateMachine.h"

namespace uml {

const bool UMLStateMachineDiagram::isCollapseStateIcon_default_ = true;
const bool UMLStateMachineDiagram::isInheritedDashed_default_ = false;
const bool UMLStateMachineDiagram::isTransitionOriented_default_ = false;
UMLStateMachineDiagram::UMLStateMachineDiagram(const QString& umlType)
    : UMLDiagram(umlType) {}

void UMLStateMachineDiagram::fromJson(const QJsonObject& json, QStringList& errorList) {
    if (json.isEmpty()) {
        return;
    }

    UMLDiagram::fromJson(json, errorList);
    UMLBehaviorDiagram::fromJson(json, errorList);
    modelElement_ = JsonSerializable::create<StateMachine>(json.value("modelElement"), errorList);

    isCollapseStateIcon_ = json.value("isCollapseStateIcon").toBool(isCollapseStateIcon_default_);
    isInheritedDashed_ = json.value("isInheritedDashed").toBool(isInheritedDashed_default_);
    isTransitionOriented_ = json.value("isTransitionOriented").toBool(isTransitionOriented_default_);
}

void UMLStateMachineDiagram::toJson(QJsonObject& json) {
    UMLDiagram::toJson(json);
    UMLBehaviorDiagram::toJson(json);
    if (modelElement_) {
        QJsonObject modelElement_json;
        modelElement_->toJson(modelElement_json);
        json.insert("modelElement", modelElement_json);
    }
    if (isCollapseStateIcon_ != isCollapseStateIcon_default_) {
        json.insert("isCollapseStateIcon", isCollapseStateIcon_);
    }
    if (isInheritedDashed_ != isInheritedDashed_default_) {
        json.insert("isInheritedDashed", isInheritedDashed_);
    }
    if (isTransitionOriented_ != isTransitionOriented_default_) {
        json.insert("isTransitionOriented", isTransitionOriented_);
    }
}

/// <summary>
/// modelElement getter
/// </summary>
shared_ptr<StateMachine> UMLStateMachineDiagram::modelElement() const {
    return modelElement_;
}

/// <summary>
/// modelElement setter
/// </summary>
void UMLStateMachineDiagram::setModelElement(shared_ptr<StateMachine> value) {
    modelElement_ = value;
}

/// <summary>
/// isCollapseStateIcon getter
/// Indicates whether UMLShapes for composite States shall contain a small icon
/// distinguishing them from non-composite States.
/// </summary>
bool UMLStateMachineDiagram::isCollapseStateIcon() const {
    return isCollapseStateIcon_;
}

/// <summary>
/// isCollapseStateIcon setter
/// Indicates whether UMLShapes for composite States shall contain a small icon
/// distinguishing them from non-composite States.
/// </summary>
void UMLStateMachineDiagram::setIsCollapseStateIcon(bool value) {
    isCollapseStateIcon_ = value;
}

/// <summary>
/// isInheritedDashed getter
/// Indicates how borders shall be rendered on UMLShapes that have an inherited
/// State as modelElement.
/// </summary>
bool UMLStateMachineDiagram::isInheritedDashed() const {
    return isInheritedDashed_;
}

/// <summary>
/// isInheritedDashed setter
/// Indicates how borders shall be rendered on UMLShapes that have an inherited
/// State as modelElement.
/// </summary>
void UMLStateMachineDiagram::setIsInheritedDashed(bool value) {
    isInheritedDashed_ = value;
}

/// <summary>
/// isTransitionOriented getter
/// Indicates whether properties of Transitions shall be shown graphically.
/// </summary>
bool UMLStateMachineDiagram::isTransitionOriented() const {
    return isTransitionOriented_;
}

/// <summary>
/// isTransitionOriented setter
/// Indicates whether properties of Transitions shall be shown graphically.
/// </summary>
void UMLStateMachineDiagram::setIsTransitionOriented(bool value) {
    isTransitionOriented_ = value;
}

} // namespace uml
